package cn.yeziji.forum.common;

import cn.yeziji.forum.common.enums.ForumCommonStatus;
import cn.yeziji.forum.exception.ForumException;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 请求返回
 *
 * @author gzkemays
 * @since 2021/12/21 17:01
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ForumResult {
  Integer code;
  String msg;
  Object data;

  public static ForumResult buildByResultEnums(ForumCommonStatus enums) {
    return ForumResult.builder().code(enums.getCode()).msg(enums.getMsg()).data(null).build();
  }

  public static ForumResult buildByException(ForumException exception) {
    return ForumResult.builder().code(exception.getCode()).msg(exception.getMsg()).data(null).build();
  }
}
